package com.ysz.server;


import com.ysz.common.constant.DynamicGroupingEnum;
import com.ysz.common.struct.ClientStruct;
import com.ysz.common.threadpool.ThreadPoolComm;
import com.ysz.server.task.ContinueScanTask;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName DynamicGroupingStruct
 * @Description 动态分组结构体
 * @Data 13:52
 * @Version 1.0
 * @Author ysz
 */
@Data
@AllArgsConstructor
@Builder
public class DynamicGrouping {

    /**
     * 动态分组的真实数据存储   key为动态分组的头数组下标
     */
    private static final ConcurrentHashMap<Integer, List<ClientStruct>> MAP = new ConcurrentHashMap<>(DynamicGroupingEnum.DYNAMIC_GROUPING_SIZE.getDynamicGroupingSize());

    public static ConcurrentHashMap<Integer, List<ClientStruct>> getMAP() {
        return MAP;
    }


    /**
     * 启动动态分组
     *
     * @date 2022/3/3 16:26
     */
    public void start() {
        this.continueScan();
    }


    private void continueScan() {
        ThreadPoolComm.SERVER_THREADS.submit(new ContinueScanTask());
    }
}
